/*
Copyright 2010  Murali Devi (profdevi@gmail.com)

This file is part of ComineGL Project.

ComineGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

ComineGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with ComineGL.  If not, see <http://www.gnu.org/licenses/>.

This code uses the irrlicht and irrklang libraries.  Please read
the libraries copyrights at 

	irrlicht library:  http://irrlicht.sourceforge.net
	irrklang library:  http://www.ambiera.com/irrklang

*/



//v1.4 copyright Comine.com 20101121U04
#ifndef MTimeEventQueue_h
#define MTimeEventQueue_h

////////////////////////////////////////////////////
#include "MIntList.h"
#include "MPtrList.h"

//******************************************************
//**  MTimeEventQueue class
//******************************************************
class MTimeEventQueue
	{
	////////////////////////////////////////////////
	unsigned int mClockTime;								// Internal Clock Time
	int mEventCount;										// Count of all the events
	struct GNode *mEventList;								// Points to a head node
	int mRemovedCount;										// Count of removed events
	
	////////////////////////////////////////////////
	void ClearObject(void);
	struct GNode *FindEvent(int eventid);					// Find given event
	bool UpdateClockTime(unsigned clocktime);				// Updateclock time
	bool LinkNode(GNode *pevent);							// link node into list
	bool UnlinkNode(GNode *pevent);							// unlink node from list
	bool CallOnEnd(GNode *pevent);							// Call on end on the node
	bool DeleteNode(GNode *pevent);							// exec OnEnd and free node
	
	////////////////////////////////////////////////
	public:
	MTimeEventQueue(void);
	~MTimeEventQueue(void);
	bool Create(unsigned int startclocktime=0);
	bool Destroy(void);
	bool EventAdd(int eventid,
			bool repeat,
			unsigned int deltatime,
			bool action(MTimeEventQueue &manager,int eventid,void *extra),
			bool onend(MTimeEventQueue &manager,int eventid,void *extra=NULL),
			void *extra=NULL);								// Add an event
	bool EventCancel(int eventid);							// Cancel Event
	bool EventCancelAll(void);								// Cancel All Events
	int GetEventCount(void);								// Get Count of events
	bool ProcessEvents(unsigned int newclocktime);			// Process all events up to abstime
	unsigned int GetClockTime(void);						// Get Clock Time for Event Queue
	bool GetEvents(MIntList &list);							// Get Event IDs
	bool GetEventsExtra(MPtrList &list);					// Get list of event extra data
	};

#endif // MTimeEventQueue_h

